import 'package:flutter/material.dart';
import 'musicItem.dart';
import 'album_list_screen.dart';

void main() {
  // 先创建AlbumList对象并添加音乐
  generateAlbumList();

  // 然后运行应用
  final AllAlbum allAlbum = AllAlbum.instance;
  allAlbum.printAllAlbum();
  runApp(AllAlbumScreen());
}

// 将generateAlbumList移出类，作为独立函数
void generateAlbumList() {
  final allAlbum = AllAlbum.instance;

  // 检查是否已经初始化过
  if (allAlbum.albumList.isNotEmpty) {
    return; // 如果已经有数据，直接返回
  }

  AlbumList album1 = AlbumList(albumName: "周杰伦", albumCover: "images/cover_zhoujielun.png", musicList: []);

  AlbumList album2 = AlbumList(albumName: "邓紫棋", albumCover: "images/cover_dengziqi.png", musicList: []);
  album2.addMusic(MusicList(
      musicName: "album2music1",
      musicAuthor: "album2author1",
      musicPath: "album2path1"
  ));
  album1.addMusic(MusicList(
      musicName: "回到过去",
      musicAuthor: "周杰伦",
      musicPath: "album1path1"
  ));
  album1.addMusic(MusicList(
      musicName: "她的睫毛",
      musicAuthor: "周杰伦",
      musicPath: "album1path2"
  ));
  album1.addMusic(MusicList(
      musicName: "夜曲",
      musicAuthor: "周杰伦",
      musicPath: "album1path3"
  ));

  allAlbum.addAlbum(album2);
  allAlbum.addAlbum(album1);
  allAlbum.sortAlbumsByName();
  allAlbum.printAllAlbum();
}